<?php
if(is_plugin_page()) {
    load_plugin_textdomain('hidepost', 'wp-content/plugins/hidepost');
    $location = get_option('siteurl') . '/wp-admin/admin.php?page=hidepost/options.php';

//Update Option
if ('process' == $_POST['stage']) {
        update_option('hidepost_content_text', trim($_POST['hidepost_content_text']));
		update_option('hidepost_link_text', trim($_POST['hidepost_link_text']));
		update_option('hidepost_role_text', trim($_POST['hidepost_role_text']));
		update_option('hidepost_hide_link', $_POST['hidepost_hide_link']);
		update_option('hidepost_allow_bot', $_POST['hidepost_allow_bot']);
		update_option('hidepost_hide_content', $_POST['hidepost_hide_content']);
    }

if (isset($_POST['hidepost_replace_sure']))//Replace
{
  $hidepost_replace_good = 1;
  echo '<div id="message" class="updated fade"><p><strong>';
  if (!isset($_POST['hidepost_replace_tag_check'])) {
       echo 'Please check the check box next to "Yes"<br/>';
       $hidepost_replace_good = 0;
  }
  if ($_POST['hidepost_new_tag'] != '[hidepost]') {
    echo 'Please input [hidepost] in New Hidepost tag<br/>';
    $hidepost_replace_good = 0;
  }
  if ($hidepost_replace_good == 1) {
      echo hidepost_search_and_replace($_POST['hidepost_old_tag'],
                              $_POST['hidepost_old_close_tag'],
                              $_POST['hidepost_new_tag']
        );
  }
  else echo 'Replace tag Failed <br/>';
  echo '</strong></p></div>';
}
//Load the config
include("option_init.php");
//Main Option Page
?>
<form name="update_hidepost" method="post" action="<?php echo $location ?>&amp;updated=true">
<input type="hidden" name="stage" value="process" />
	<div class="wrap">
		<h2>HidePost Options</h2>
		<p>
			<?php
				if ($hidepost_hide_content!=1){$checked="";} else {$checked="checked";}
			?>
			<input name="hidepost_hide_content" type="checkbox" id="hidepost_hide_content" value="1" <?php echo $checked; ?>/>
			<label><strong>Enable Hidepost</strong> (Uncheck if you want to disable HidePost).</label>
		</p>
		<p>
			<?php
				if ($hidepost_hide_link!=1){$checked="";} else {$checked="checked";}
			?>
			<input name="hidepost_hide_link" type="checkbox" id="hidepost_hide_link" value="1" <?php echo $checked; ?>/>
			<label><strong>Protect Link</strong> (Only logged in member can see link on your post).</label>
		</p>
		<p>
			<?php
				if ($hidepost_allow_bot!=1){$checked="";} else {$checked="checked";}
			?>
			<input name="hidepost_allow_bot" type="checkbox" id="hidepost_allow_bot" value="1" <?php echo $checked; ?>/>
			<label><strong>Allow bot</strong> (This will allow Bot engine like Google and Yahoo can access your protected content).</label>
		</p>
		<p>
			<label><font size=3>Protect content show text:  </font></label>
		</p>
		<p>
			<span>&nbsp;&nbsp;</span>
			<input name="hidepost_content_text" type="text" id="hidepost_content_text" value="<?php echo the_view($hidepost_content_text); ?>" size="100" />
		</p>
		<p>
			<label><font size=3>Protect content with User role level:  </font></label>
		</p>
		<p>
			<span>&nbsp;&nbsp;</span>
			<input name="hidepost_role_text" type="text" id="hidepost_role_text" value="<?php echo the_view($hidepost_role_text); ?>" size="100" />
		</p>
		<p>
			<label><font size=3>Protect link show text:  </font></label>
		</p>
		<p>
			<span>&nbsp;&nbsp;</span>
			<input name="hidepost_link_text" type="text" id="hidepost_link_text" value="<?php echo the_view($hidepost_link_text); ?>" size="100" />
		</p>
		<p><strong>Note: </strong></p>
		<p>%login% = Link to you Login page.</p>
		<p>		 %register% = Link to you Register page.</p>
		<p>		 %role% = Display user role requirement like Administrator or Registered.</p>
		<p>		 You can only use some simple HTML code in the show text.</p>
		<p><strong>UserLevel</strong></p>
		<p>You can use [hidepost=level][/hidepost] where level = 0->9</p>
		<p>0 = Registered Member</p>
		<p>....</p>
		<p>9 = Administrator</p>
		<p>More help can be found on http://codex.wordpress.org/User_Levels</p>
		<p class="submit">
            <input type="submit" name="Submit" value="Save Options  &raquo;" />
        </p>
	</div>
</form>

<form name="hidepost_replace_tag" method="post" action="<?php echo $location ?>">
<input type="hidden" name="hidepost_replace_sure" />
 <div class="wrap">
  <h2>Replace old Tag with [hidepost]</h2>
    <p>
        <input type="text" id="hidepost_old_tag" name ="hidepost_old_tag" value="<?php if (get_option('open_tag')) echo get_option('open_tag');?>"/>
        <label><strong> Your old Tag </strong></label>
        <input type="text" id="hidepost_old_close_tag" name="hidepost_old_close_tag" value="<?php if (get_option('close_tag')) echo get_option('close_tag');?>" />
        <label><strong> Your old close Tag </strong></label>
    </p><p>
        <input type="text" id="hidepost_new_tag" name ="hidepost_new_tag" value=""/>
        <label><strong> New HidePost tag (Just input [hidepost]) </strong></label>
    </p><p>
        <input type="checkbox" name="hidepost_replace_tag_check" value="yes" />
        <label>&nbsp;Yes (Check if you want to Replace)</label>
    </p>
        <input type="submit" name ="hidepost_replace_submit" value="Replace"/>
    <p style="text-align: left; color: red">
		<strong>WARNING:</strong><br />
		You should backup your Wordpress database before using this.
    </p>
  </div>
</form>
<?php
}
?>
